package com.hk.springtrains.websocket;


import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
//不仅配置了WebSocket，还启用STOMP消息功能
@EnableWebSocketMessageBroker
public class WeSocketStompConfig extends AbstractWebSocketMessageBrokerConfigurer{


    /**
     * 注册STOMP端点，客户端在订阅或发布消息到目的地路径前，要连接该端点
     * @param registry
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/trains").withSockJS();
    }


    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //配置简单消息代理，默认启用/topic消息代理。将处理前缀为/topic与/queue的消息
        registry.enableSimpleBroker("/queue","/topic");

        //设置发往应用程序的消息带/app前缀
        registry.setApplicationDestinationPrefixes("/app");
    }
}
